#include "threadPool.h"

int mysql_client_init(MYSQL*** mysql, int work_num) {
    MYSQL** mysql_pool = (MYSQL**)calloc(work_num, sizeof(MYSQL*));
    if (!mysql_pool) {
        fprintf(stderr, "calloc mysql_pool failed in mysql.c:mysql_init.\n");
        return -1;
    }
    *mysql = mysql_pool;
    return 0;
}


int mysql_query_c(MYSQL* conn, char* sql, SQL_RES* s){
    int qret = mysql_query(conn, sql);
  if (qret != 0) {
      fprintf(stderr, "mysql_query: %s\n", mysql_error(conn));
      return -1;
    }
    MYSQL_RES *table = mysql_store_result(conn);
    int n = mysql_num_rows(table);
    int m = mysql_num_fields(table);
    s->table = table;
    s->row_num = n;
    s->col_num = m;
    return n;
}
